#ifndef LOCALCURRENCY_H
#define LOCALCURRENCY_H

#include "lib.h"

#define MAX_CURR_SYMB 3
#define MAX_CHIPS 5
#define MAX_CHIPS_STR 100

// information on Local Currency settings
struct localCurrency_V1 {
	char int_curr_symbol[MAX_CURR_SYMB+1];
	char currency_symbol[MAX_CURR_SYMB+1];		
	char decimal_sep;
	char thousands_sep;
	uint8 grouping;
	bool8 frac_digits;
	bool8 cs_precedes;
	bool8 sep_by_space;
};


// information on Local Currency settings
struct localCurrency {
	String int_curr_symbol;
	String currency_symbol;
	String decimal_sep;
	String thousands_sep;
	uint8 grouping;
	bool8 frac_digits;
	bool8 cs_precedes;
	bool8 sep_by_space;
    String subcurrency_symbol;  // kharmon.  11-18-05.  #7145.  Added subcurrency info to login response.
    bool8  scs_precedes;
    bool8  scs_sep_by_space;
};

class LocalCurrency
{
public:
	static bool8 convert( localCurrency_V1* lcv1, localCurrency* lc)
	{
		if (!lcv1 || !lc)
			return false;

		StringConversions::convert(lcv1->int_curr_symbol,	lc->int_curr_symbol,	MAX_CURR_SYMB+1);
		StringConversions::convert(lcv1->currency_symbol,	lc->currency_symbol,	MAX_CURR_SYMB+1);
		
		lcv1->decimal_sep	= (char)lc->decimal_sep[0];
		lcv1->thousands_sep = (char)lc->thousands_sep[0];
	
		lcv1->grouping = (char)lc->grouping;
		lcv1->frac_digits = (char)lc->frac_digits;
		lcv1->cs_precedes = (char)lc->cs_precedes;
		lcv1->sep_by_space = (char)lc->sep_by_space;

		return true;
	}

	static bool8 convert( localCurrency* lcTo, localCurrency* lc)
	{
		if (!lcTo || !lc)
			return false;

		lcTo->int_curr_symbol = lc->int_curr_symbol;
		lcTo->currency_symbol =	lc->currency_symbol;
		lcTo->decimal_sep	= lc->decimal_sep;
		lcTo->thousands_sep = lc->thousands_sep;
		lcTo->grouping = lc->grouping;
		lcTo->frac_digits = lc->frac_digits;
		lcTo->cs_precedes = lc->cs_precedes;
		lcTo->sep_by_space = lc->sep_by_space;

        // kharmon.  11-18-05.  #7145.  Added subcurrency info to login response.
        lcTo->subcurrency_symbol = lc->subcurrency_symbol;
        lcTo->scs_precedes       = lc->scs_precedes;
        lcTo->scs_sep_by_space   = lc->scs_sep_by_space;

		return true;
	}


	static int32 serialize( localCurrency* lc, uint8* buf )
	{
		int32 used = 0;

		if (!lc)
			return used;

		used += lc->int_curr_symbol.serialize( buf + used );
		used += lc->currency_symbol.serialize( buf + used );
		used += lc->decimal_sep.serialize( buf + used );
		used += lc->thousands_sep.serialize( buf + used );

		buf[ used++ ] = (uint8)lc->grouping;
		buf[ used++ ] = (uint8)lc->frac_digits;
		buf[ used++ ] = (uint8)lc->cs_precedes;
		buf[ used++ ] = (uint8)lc->sep_by_space;

        // kharmon.  11-18-05.  #7145.  Added subcurrency info to login response.
        used += lc->subcurrency_symbol.serialize( buf + used );
        buf[ used++ ] = (uint8) lc->scs_precedes;
        buf[ used++ ] = (uint8) lc->scs_sep_by_space;
		
		return used;
	}

	static int32 deserialize( localCurrency* lc, uint8* buf )
	{
		int32 used = 0;

		if (!lc)
			return used;

		used += lc->int_curr_symbol.deserialize( buf + used );
		used += lc->currency_symbol.deserialize( buf + used );
		used += lc->decimal_sep.deserialize( buf + used );
		used += lc->thousands_sep.deserialize( buf + used );

		lc->grouping = (uint8)buf[ used++ ];
		lc->frac_digits = (bool8)buf[ used++ ];
		lc->cs_precedes = (bool8)buf[ used++ ];
		lc->sep_by_space = (bool8)buf[ used++ ];

        // kharmon.  11-18-05.  #7145.  Added subcurrency info to login response.
        used += lc->subcurrency_symbol.deserialize( buf + used );
        lc->scs_precedes     = (uint8) buf[ used++ ];
        lc->scs_sep_by_space = (uint8) buf[ used++ ];

		return used;
	}
};

#endif